package com.luban.service;

import javax.annotation.PostConstruct;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanClassLoaderAware;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.BeanFactoryAware;
import org.springframework.beans.factory.BeanNameAware;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

@Component
@Scope(value = ConfigurableBeanFactory.SCOPE_SINGLETON)
public class UserService implements BeanNameAware, BeanClassLoaderAware, BeanFactoryAware, InitializingBean {

	private String beanName;

	@Autowired
	private ShoppingService shoppingService;

	//@Autowired
	private OrderService orderService;

	public OrderService getOrderService() {
		return orderService;
	}

	public void setOrderService(OrderService orderService) {
		this.orderService = orderService;
	}

	@Override
	public void setBeanName(String name) {
		this.beanName = name;
		System.out.println(this.beanName + ":beanName 设置");
	}

	@Override
	public void setBeanClassLoader(ClassLoader classLoader) {
		System.out.println(this.beanName + ":classLoader 设置");
	}

	@Override
	public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
		System.out.println(this.beanName + ":beanFactory 设置");
	}

	@PostConstruct
	public void postConstruct() {
		System.out.println(this.beanName + ":postConstruct:初始化之前");
	}

	@Override
	public void afterPropertiesSet() throws Exception {
		System.out.println(this.beanName + ":afterPropertiesSet:初始化中");
	}

	public void initMethod() {
		System.out.println(this.beanName + ":initMethod:初始化中");
	}

	public void test() {
		System.out.println(this.beanName + ":test");
		System.out.println(this.beanName + ":orderService:" + orderService);
	}
}
